package com.crm.service.impl;

import com.crm.dto.ClueGainDto;
import com.crm.entity.Clue;
import com.crm.mapper.FakeMapper;
import com.crm.mapper.UserMapper;
import com.crm.result.CluePage;
import com.crm.result.PageResultTow;
import com.crm.service.FakeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FakeServiceImpl implements FakeService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private FakeMapper fakeMapper;
    @Override
    public PageResultTow getFakePoolByPage(CluePage page) {
        if (page.getParams().get("beginCreateTime") != ""){
            page.setBeginCreateTime(page.getParams().get("beginCreateTime"));
        }else {
            page.setBeginCreateTime(null);
        }
        if (page.getParams().get("endCreateTime") != ""){
            page.setEndCreateTime(page.getParams().get("endCreateTime"));
        }else {
            page.setEndCreateTime(null);
        }
        List<Long> longs = userMapper.selectByName(page.getOwner());
        if (longs.size()==0){
            longs.add(-1L);
            page.setUserids(longs);
        }else {
            page.setUserids(longs);
        }
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
//        List<Clue> clues = cluesMapper.selectCluesByCondition(page.getParams().getBeginCreateTime(),page.getParams().getEndCreateTime());
//        PageInfo<Clue> pageInfo = new PageInfo<>(clues);
        List<Clue> clues = fakeMapper.selectByConditions(page); // 直接传入 CluePage
        PageInfo<Clue> pageInfo = new PageInfo<>(clues);
        PageResultTow pageResultTow = new PageResultTow(200, "查询成功", null, pageInfo.getTotal(), pageInfo.getList());

        return pageResultTow;
    }

    @Override
    public void putGain(ClueGainDto clueGainDto) {
        fakeMapper.putGain(clueGainDto.getIds());
    }
}
